package com.zjy.heath_ms.configure;

import com.zjy.heath_ms.interceptor.CrossInterceptor;
import com.zjy.heath_ms.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 项目名 heath_ms
 * 类名  InterceptorConfig
 * 作者 lzq
 * 创建时间  2025/5/10 13:19
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 向容器中添加跨域验证拦截器
     * @return
     */
    @Bean
    public CrossInterceptor crossInterceptor()
    {
        return new CrossInterceptor();
    }

    /**
     * 向容器中添加登录验证拦截器
     * @return
     */
    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 跨域拦截规则
        registry.addInterceptor(crossInterceptor()).addPathPatterns("/**");
        // 登录拦截规则
        registry.addInterceptor(loginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/register");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
